
use "Latino survey.dta", clear

//Administrative variables
gen speeder=0
replace speeder=1 if Duration__in_seconds_<460

//Demographics
gen employed=0
replace employed=1 if Q84_1 ==1
replace employed=1 if Q84_2 ==1

gen woman=0
replace woman=1 if Q2==2

gen parentsimm=Q83

gen spanishlang=0
replace spanishlang=1 if Q93_3==1

gen mexican=Q4_1
gen puertorican= Q4_9
gen cuban=Q4_8
gen dominican=Q4_5

gen nationality=4
replace nationality=0 if mexican==1
replace nationality=1 if puertorican==1
replace nationality=2 if cuban==1
replace nationality=3 if dominican==1
label define nationalityl 0 "Mexican" 1 "PuertoRican"  2 "Cuban"  3 "Dominican" 4 "Other"
label values nationality nationalityl

gen imm=0
replace imm=1 if Q7==2

gen education = 1 if Q81 == 1
replace education = 2 if Q81 == 4
replace education = 3 if Q81 == 5
replace education = 4 if Q81 == 6
replace education = 5 if Q81 == 7
replace education = 6 if Q81 == 8
label define education 1 " Did not graduate from high school" 2 "High school graduate"  3 "Some college, but no degree"  4 "2-year college degree" 5 "4-year college degree" 6 "Postgraduate degree (MA, MBA, MD, JD, P"
label values education education 
gen edu=education
label values edu education 

gen income_new = 1 if Q85 == 1
replace income_new = 2 if Q85 == 3
replace income_new = 3 if Q85 == 4 | Q85 == 16
replace income_new = 4 if Q85 == 5
replace income_new = 5 if Q85 == 6
replace income_new = 6 if Q85 == 11
replace income_new = 7 if Q85 == 13
replace income_new = 8 if Q85 == 15
label define income_new 1 "Less than $20,000" 2 "$20,000 - $39,999" 3 "$40,000 - $59,999" 4 "$60,000 - $79,999" 5 "$80,000 - $99,999" 6 "$100,000 - $149,999" 7  "$150,000 - $199,999" 8 "$200,000 or more"
label values income_new income_new 
replace income=income_new


decode Q82, generate(yearofbirth)
destring yearofbirth, replace
gen age=2019-yearofbirth

//Party ID

gen PID=Q86
replace PID=2 if PID==5
label define PIDl 1 "R" 2 "I"  3 "D"
label values PID PIDl 

gen havePID=0
replace havePID=1 if PID==1
replace havePID=1 if PID==3


 //Pre-treatment interest
gen interest=Q19
replace interest=6.668335 if interest==.
gen interestAP=(Q52)/10
gen interestIP=(Q53)/10


//Participation variables

gen previousvote=Q9
replace previousvote=0 if Q9==2
replace previousvote=.5 if Q9==4

alpha  Q49_1 Q49_2 Q49_3 Q49_4 Q49_5 Q49_6 , i g(participation)
replace participation=abs(participation-5)/4

gen Donate=Q49_6
replace Donate=abs(Donate-5)/4
gen SocialMedia=Q49_5
replace SocialMedia=abs(SocialMedia-5)/4
gen Petition=Q49_4
replace Petition=abs(Petition-5)/4
gen Protest=Q49_3
replace Protest=abs(Protest-5)/4
gen Discuss=Q49_2
replace Discuss=abs(Discuss-5)/4
gen Volunteer=Q49_1
replace Volunteer=abs(Volunteer-5)/4

gen willvote=Q50 
replace willvote=(abs(willvote-4))/3

gen voteethusiasm= Q51
replace voteethusiasm=(abs(voteethusiasm-3))/2



/////Identity

gen immID=Q10
gen foldimmID=abs(Q10-5)
gen foldimmIDmedian=abs(Q10-5)

gen ethID=Q12 
gen foldethID=abs(Q12-5)

gen natID=Q14
gen foldnatID=abs(Q14-5)

gen AmID= Q18
gen foldAmID=abs(Q14-5)


gen immLinked= Q11
replace immLinked=4 if immLinked==5
replace immLinked=(abs(immLinked-4))/3

gen ethLinked= Q13
replace ethLinked=4 if ethLinked==5
replace ethLinked=(abs(ethLinked-4))/3

gen natLinked= Q15
replace natLinked=4 if natLinked==5
replace natLinked=(abs(natLinked-4))/3


//Low Medium High identifiers
gen ethIDcat=.
replace ethIDcat=0 if ethID<6.1   
replace ethIDcat=1 if ethID>6  
replace ethIDcat=2 if ethID==10  


//treatments
gen ImmTreatment=0
replace ImmTreatment=1 if FL_7_DO_T2_ImmigrationRep==1
replace ImmTreatment=1 if FL_7_DO_T3_ImmigrationNP==1

gen EthTreatment=0
replace EthTreatment=1 if FL_7_DO_T14_EthnicityRep==1
replace EthTreatment=1 if FL_7_DO_T15_EthnicityNP==1


gen EconTreatment=0
replace EconTreatment=1 if FL_7_DO_T8_EconomyRep==1
replace EconTreatment=1 if FL_7_DO_T9_EconomyNP==1

gen treatment=.
replace treatment=0 if FL_7_DO_T8_EconomyRep==1 | FL_7_DO_T9_EconomyNP==1 
replace treatment=1 if FL_7_DO_T14_EthnicityRep==1 | FL_7_DO_T15_EthnicityNP==1 
replace treatment=2 if FL_7_DO_T2_ImmigrationRep==1 | FL_7_DO_T3_ImmigrationNP==1 
label define Treatmentl 0 "Economy" 1 "Ethnicity"  2 "Immigration"
label values treatment Treatmentl 

gen smalltreatment=treatment
replace  smalltreatment=1 if treatment==2


gen Rcand=0
replace Rcand=1 if FL_7_DO_T2_ImmigrationRep==1
replace Rcand=1 if FL_7_DO_T8_EconomyRep==1
replace Rcand=1 if FL_7_DO_T14_EthnicityRep==1

gen Icand=0
replace Icand=1 if FL_7_DO_T3_ImmigrationNP==1
replace Icand=1 if FL_7_DO_T9_EconomyNP==1
replace Icand=1 if FL_7_DO_T15_EthnicityNP==1  

gen Cparty=.
replace Cparty=0 if Rcand==1
replace Cparty=1 if Icand==1

label define Cpartyl 0 "Republican" 1 "No Party" 
label values Cparty Cpartyl 


//manipulation check
gen manipulation_topic=0
replace manipulation_topic=1 if Q56==1 & treatment==1
replace manipulation_topic=1 if Q56==1 & treatment==2
replace manipulation_topic=1 if Q56==4 & treatment==1
replace manipulation_topic=1 if Q56==4 & treatment==2
replace manipulation_topic=1 if Q56==2 & treatment==0

gen manipulation_party=0
replace manipulation_party=1 if Q57==1 & Cparty==0
replace manipulation_party=1 if Q57==3 & Cparty==1

//attention check
gen attentioncheck=0
replace attentioncheck=1 if Q73==3


